import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)


export const IndexRouter=[
  {
    path:'menu',
    component:()=>import('../twopages/2-menu/menu.vue'),
    meta:{
      title:'菜单管理'
    }
  },
  {
    path:'role',
    component:()=>import('../twopages/3-role/role.vue'),
    meta:{
      title:'角色管理'
    }
  },
  {
    path:'manage',
    component:()=>import('../twopages/4-manage/manage.vue'),
    meta:{
      title:'管理员管理'
    }
  },
  {
    path:'cate',
    component:()=>import('../twopages/5-cate/cate.vue'),
    meta:{
      title:'商品分类'
    }
  },
  {
    path:'specs',
    component:()=>import('../twopages/6-specs/specs.vue'),
    meta:{
      title:'商品规格'
    }
  },
  {
    path:'goods',
    component:()=>import('../twopages/7-goods/goods.vue'),
    meta:{
      title:'商品管理'
    }
  },
  {
    path:'vip',
    component:()=>import('../twopages/8-vip/vip.vue'),
    meta:{
      title:'会员管理'
    }
  },
  {
    path:'banner',
    component:()=>import('../twopages/9-banner/banner.vue'),
    meta:{
      title:'轮播图管理'
    }
  },
  {
    path:'seckill',
    component:()=>import('../twopages/10-seckill/seckill.vue'),
    meta:{
      title:'秒杀活动'
    }
  },
]

const routes = [
      {
        path:'/login',
        component:()=>import('../onepages/login.vue')
      },
      {
        path:'/',
        component:()=>import('../onepages/index.vue'),
        children:[
          {
            path:'home',
            component:()=>import('../twopages/1-home/home.vue'),
          },

          ...IndexRouter,

          {
            path:'',
            redirect:'home'
          },
        ]
      },
      {
        path:'*',
        redirect:'/login'
      }
     
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
      if(to.path == '/login'){
        next();
        return;
      }
      if(sessionStorage.getItem('userinfo')){
        next();
        return
      }
      next('/login')
})


export default router
